<?php

namespace App\Entity\Lang;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Base\Annotation\Common;
use App\Repository\Lang\LangPageRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass=LangPageRepository::class)
 */
class LangPage
{
    /**
     * @Common(cnName="#",listType="text",editType="text")
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @Groups({"lang"})
     */
    private $id;

    /**
     * @Common(cnName="语言包",listType="text",editType="text")
     * @ORM\ManyToOne(targetEntity=LangPack::class, inversedBy="pages")
     * @ORM\JoinColumn(nullable=false)
     * @Groups({"lang"})
     */
    private $pack;

    /**
     * @Common(cnName="页面名称",listType="text",editType="text",width="200")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"lang"})
     */
    private $name;

    /**
     * @Common(cnName="页面key值",listType="text",editType="text",width="200")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"lang"})
     */
    private $page;


    /**
     * @Common(cnName="语言包名称",listType="text",editType="text")
     * @ORM\OneToMany(targetEntity="App\Entity\Lang\Translation",mappedBy="page")
     * @Groups({"lang"})
     */
    private $list;

    public function __construct()
    {
        $this->list = new ArrayCollection();
    }


    public function getId(): ?int
    {
        return $this->id;
    }

    public function getPack(): ?LangPack
    {
        return $this->pack;
    }

    public function setPack(?LangPack $pack): self
    {
        $this->pack = $pack;

        return $this;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(?string $name): self
    {
        $this->name = $name;

        return $this;
    }

    /**
     * @return Collection|Translation[]
     */
    public function getList(): Collection
    {
        return $this->list;
    }

    public function addList(Translation $list): self
    {
        if (!$this->list->contains($list)) {
            $this->list[] = $list;
            $list->setPage($this);
        }

        return $this;
    }

    public function removeList(Translation $list): self
    {
        if ($this->list->contains($list)) {
            $this->list->removeElement($list);
            // set the owning side to null (unless already changed)
            if ($list->getPage() === $this) {
                $list->setPage(null);
            }
        }

        return $this;
    }

    public function getPage(): ?string
    {
        return $this->page;
    }

    public function setPage(?string $page): self
    {
        $this->page = $page;

        return $this;
    }
}
